package com.csi.service.impl;

import com.csi.dao.impl.OrderDaoImpl;
import com.csi.dao.OrderDao;
import com.csi.domain.Order;
import com.csi.service.OrderService;

import java.sql.SQLException;
import java.util.List;

public class OrderServiceImpl implements OrderService {
    @Override
    public List<Order> findAll() {
        OrderDao orderDao=new OrderDaoImpl();
        List<Order> all = null;
        try {
            all = orderDao.findAll();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return all;
    }

    @Override
    public int delete(int orderId) {
        OrderDao orderDao=new OrderDaoImpl();
        int delete = 0;
        try {
            delete = orderDao.delete(orderId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return delete;
    }

    @Override
    public int insert(Order order) {
        OrderDao orderDao=new OrderDaoImpl();
        int insert = 0;
        try {
            insert = orderDao.insert(order);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return insert;
    }

    @Override
    public int update(Order order) {
        OrderDao orderDao=new OrderDaoImpl();
        int update = 0;
        try {
            update = orderDao.update(order);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return update;
    }
}
